From: Dirkjan Ochtman Date: Sat, 14 Apr 2018 08:27:33 +0000 (+0200) Subject: Store message format as enum in BuildConfig X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~1^2~10^2~12 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=85be6a17465398fe523ae97b3c38988789d4e9c4;p=cargo.git Store message format as enum in BuildConfig --- diff --git a/src/bin/cargo/command_prelude.rs b/src/bin/cargo/command_prelude.rs index 2f6a04624..8157dcdb4 100644 --- a/src/bin/cargo/command_prelude.rs +++ b/src/bin/cargo/command_prelude.rs @@ -4,8 +4,8 @@ use std::fs; use clap::{self, SubCommand}; use cargo::CargoResult; use cargo::core::Workspace; -use cargo::ops::{CompileFilter, CompileMode, CompileOptions, MessageFormat, NewOptions, Packages, - VersionControl}; +use cargo::core::compiler::MessageFormat; +use cargo::ops::{CompileFilter, CompileMode, CompileOptions, NewOptions, Packages, VersionControl}; use cargo::util::paths; use cargo::util::important_paths::find_root_manifest_for_wd; diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index b23b1256d..78dfe759b 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -231,7 +231,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes ); let build_scripts = super::load_build_deps(cx, unit); let kind = unit.kind; - let json_messages = bcx.build_config.json_messages; + let json_messages = bcx.build_config.json_messages(); // Check to see if the build script has already run, and if it has keep // track of whether it has told us about some explicit dependencies diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 4e87f66c6..82cbbc43d 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -64,7 +64,7 @@ pub struct BuildConfig { /// Whether we are running tests pub test: bool, /// Whether to print std output in json format (for machine reading) - pub json_messages: bool, + pub message_format: MessageFormat, } impl BuildConfig { @@ -132,7 +132,7 @@ impl BuildConfig { target: target_config, release: false, test: false, - json_messages: false, + message_format: MessageFormat::Human, }) } @@ -152,6 +152,16 @@ impl BuildConfig { .map(|s| s.as_str()) .unwrap_or(self.host_triple()) } + + pub fn json_messages(&self) -> bool { + self.message_format == MessageFormat::Json + } +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum MessageFormat { + Human, + Json, } /// Information required to build for a target @@ -382,7 +392,7 @@ fn rustc<'a, 'cfg>( let dep_info_loc = fingerprint::dep_info_loc(&mut cx, unit); rustc.args(&cx.bcx.rustflags_args(unit)?); - let json_messages = cx.bcx.build_config.json_messages; + let json_messages = cx.bcx.build_config.json_messages(); let package_id = unit.pkg.package_id().clone(); let target = unit.target.clone(); @@ -569,7 +579,7 @@ fn link_targets<'a, 'cfg>( .into_iter() .map(|s| s.to_owned()) .collect(); - let json_messages = bcx.build_config.json_messages; + let json_messages = bcx.build_config.json_messages(); Ok(Work::new(move |_| { // If we're a "root crate", e.g. the target of this compilation, then we @@ -876,7 +886,7 @@ fn build_base_args<'a, 'cfg>( ColorChoice::CargoAuto => {} } - if bcx.build_config.json_messages { + if bcx.build_config.json_messages() { cmd.arg("--error-format").arg("json"); } diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index c13ad0a35..87c37b0fe 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -27,7 +27,7 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; use core::compiler::{BuildConfig, BuildContext, Compilation, Context, DefaultExecutor, Executor}; -use core::compiler::{Kind, Unit}; +use core::compiler::{Kind, MessageFormat, Unit}; use core::profiles::{ProfileFor, Profiles}; use core::resolver::{Method, Resolve}; use core::{Package, Source, Target}; @@ -181,12 +181,6 @@ impl CompileMode { } } -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum MessageFormat { - Human, - Json, -} - #[derive(Clone, PartialEq, Eq, Debug)] pub enum Packages { Default, @@ -341,7 +335,7 @@ pub fn compile_ws<'a>( let mut build_config = BuildConfig::new(config, jobs, &target, Some(rustc_info_cache))?; build_config.release = release; build_config.test = mode == CompileMode::Test || mode == CompileMode::Bench; - build_config.json_messages = message_format == MessageFormat::Json; + build_config.message_format = message_format; let default_arch_kind = if build_config.requested_target.is_some() { Kind::Target } else { diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index 19774f5e3..1cb3f24fb 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -10,7 +10,7 @@ use git2; use tar::{Archive, Builder, EntryType, Header}; use core::{Package, Source, SourceId, Workspace}; -use core::compiler::DefaultExecutor; +use core::compiler::{DefaultExecutor, MessageFormat}; use sources::PathSource; use util::{self, internal, Config, FileLock}; use util::paths; @@ -347,7 +347,7 @@ fn run_verify(ws: &Workspace, tar: &FileLock, opts: &PackageOpts) -> CargoResult required_features_filterable: true, }, release: false, - message_format: ops::MessageFormat::Human, + message_format: MessageFormat::Human, mode: ops::CompileMode::Build, target_rustdoc_args: None, target_rustc_args: None, diff --git a/src/cargo/ops/mod.rs b/src/cargo/ops/mod.rs index c72d03a89..08e65ba54 100644 --- a/src/cargo/ops/mod.rs +++ b/src/cargo/ops/mod.rs @@ -1,6 +1,6 @@ pub use self::cargo_clean::{clean, CleanOptions}; pub use self::cargo_compile::{compile, compile_with_exec, compile_ws, CompileOptions}; -pub use self::cargo_compile::{CompileFilter, CompileMode, FilterRule, MessageFormat, Packages}; +pub use self::cargo_compile::{CompileFilter, CompileMode, FilterRule, Packages}; pub use self::cargo_read_manifest::{read_package, read_packages}; pub use self::cargo_run::run; pub use self::cargo_install::{install, install_list, uninstall};